//
//  RZQFindCirleViewController.m
//  LastOne
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "RZQFindCirleViewController.h"
#import "RZQDataCollectionViewCell.h"
#import "CirleModel.h"
#import "FitHeader.h"
#import "HTTPMethod.h"
#import <UIButton+WebCache.h>
#import "RZQFindWebViewController.h"
#import "GiFHUD.h"
@interface RZQFindCirleViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property(nonatomic, strong)UICollectionView *DataCollectionView;

@property(nonatomic, strong)NSMutableArray *dataSoure;

@end

@implementation RZQFindCirleViewController

#pragma mark 网络请求
-(void)getNet
{
    [GiFHUD show];
    _dataSoure = [NSMutableArray array];
    [HTTPMethod getDataByString:[NSString stringWithFormat:@"http://app.qdaily.com/app/radars/index/%ld/0.json", _index] BodyDic:nil WithDataBlock:^(id data) {
        
        NSDictionary *dic = [data objectForKey:@"response"];
        NSDictionary *dic1 = [dic objectForKey:@"feeds"];
        NSArray *array = [dic1 objectForKey:@"list"];
        
        for (NSDictionary *Dic in array) {
            CirleModel *cirle  = [[CirleModel alloc]init];
            NSDictionary *postDic = [Dic objectForKey:@"post"];
            
            [cirle setValuesForKeysWithDictionary:postDic];
            cirle.image = [Dic objectForKey:@"image"];
            cirle.type = [Dic objectForKey:@"type"];
            [_dataSoure addObject:cirle];
        }
       [_DataCollectionView reloadData];
        [GiFHUD dismiss];
    }];
}
#pragma mark 创建瀑布流
- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self getNet];
    self.view.backgroundColor = [UIColor whiteColor];
    UICollectionViewFlowLayout *dataFlowLayout = [[UICollectionViewFlowLayout alloc]init];
    dataFlowLayout.minimumInteritemSpacing = 5 ;
    dataFlowLayout.minimumLineSpacing = 5;
    dataFlowLayout.sectionInset = UIEdgeInsetsMake(5 , 5 , 5, 5 );
    
    _DataCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 113 * FitHeight) collectionViewLayout:dataFlowLayout];
    _DataCollectionView.delegate = self;
    _DataCollectionView.dataSource = self;
        _DataCollectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_DataCollectionView];
    [GiFHUD setGifWithImageName:@"loading.gif"];
    
    [_DataCollectionView registerClass:[RZQDataCollectionViewCell class] forCellWithReuseIdentifier:@"rzqIdentifier"];
    
    
    
    
    // Do any additional setup after loading the view.
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    
    return  CGSizeMake(ScreenWidth / 2 - 10 * FitWidth  , 200 * FitHeight);
     

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RZQDataCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"rzqIdentifier" forIndexPath:indexPath];
    cell.cirData = _dataSoure[indexPath.row];
    return cell;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataSoure.count;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    RZQFindWebViewController *rzq = [[RZQFindWebViewController alloc]init];
    [self.navigationController pushViewController:rzq animated:YES];
    rzq.flag = [_dataSoure[indexPath.row]Id];

  
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
